document.addEventListener('DOMContentLoaded', function () {
    const namesWithWeights = [
        { "name": '你第一次看到TA的时候，有没有心里小鹿乱撞？', weight: 1 },
        { "name": "你第一次注意到我是什么时候？", "weight": 1 },
        { "name": "你最喜欢的约会方式是什么？", "weight": 1 },
        { "name": "你认为我最大的优点是什么？", "weight": 1 },
        { "name": "你最近做的一个梦是什么？", "weight": 1 },
        { "name": "如果可以和世界上任何一个人共进晚餐，你会选择谁？", "weight": 1 },
        { "name": "今天晚上要做什么。", "weight": 1 },
        { "name": "你会做菜么。", "weight": 1 },
        { "name": "每天上网几个小时。", "weight": 1 },
        { "name": "你们家里谁的脾气最大。", "weight": 1 },
        { "name": "异性知己有几个。", "weight": 1 },
        { "name": "上厕所后洗手么。", "weight": 1 },
        { "name": "你最受不了别人对你做什么。", "weight": 1 },
        { "name": "觉得失去什么最可怕。", "weight": 1 },
        { "name": "你最喜欢的歌曲是哪首？", "weight": 1 },
        { "name": "你们家里谁掌管钱财。", "weight": 1 },
        { "name": "如果你现在心情不好。会怎样。", "weight": 1 },
        { "name": "你最喜欢的小说是什么。", "weight": 1 },
        { "name": "你最害怕的事情或东西是什么。(说出3件。)", "weight": 1 },
        { "name": "到目前为止写过多少封情书。", "weight": 1 },
        { "name": "自己做过最丢脸的事是什么。", "weight": 1 },
        { "name": "你希望你现在是多少岁。", "weight": 1 },
        { "name": "用四个字形容你现在的生活状态。", "weight": 1 },
        { "name": "世界上最大的悲剧是什么。", "weight": 1 },
        { "name": "晚上睡觉要上几次厕所。", "weight": 1 },
        { "name": "在座你最想打的人是谁。", "weight": 1 },
        { "name": "收到过最难忘的礼物是什么。", "weight": 1 },
        { "name": "你最短的一次恋爱是什么情况。", "weight": 1 },
        { "name": "你喜欢谁。", "weight": 1 },
        { "name": "如果有来生，你选择当什么？", "weight": 1 },
        { "name": "如果让你选择做一个电影中的角色，你会选谁呢？", "weight": 1 },
        { "name": "如果有一天我和你吵架，你会怎么办？", "weight": 1 },
        { "name": "哭得最伤心的是哪一次？为什么？", "weight": 1 },
        { "name": "如果跟你喜欢的人约会，碰到前任的男（女）朋友，会有什么表现？", "weight": 1 },
        { "name": "如果有一天我对你说我爱上你了，你怎么办？", "weight": 1 },
        { "name": "自己最丢人的事", "weight": 1 },
        { "name": "最后一次发自内心的笑是什么时候？", "weight": 1 },
        { "name": "愿意为爱情牺牲到什么程度", "weight": 1 },
        { "name": "朋友和男/女朋友哪个重要", "weight": 1 },
        { "name": "如果让你拥有一种超潜质，你愿意拥有什么呢？", "weight": 1 },
        { "name": "如何向喜欢的人表白？", "weight": 1 },
        { "name": "如果有一天自我觉得自我的某一次选取是错的，但是此刻已经再也无法重新来，那该怎样办？", "weight": 1 },
        { "name": "此刻你最喜欢的人是谁？", "weight": 1 },
        { "name": "以前有过最被感动的事是什么？", "weight": 1 },
        { "name": "我在你眼里什么样？", "weight": 1 },
        { "name": "你觉得自我最郁闷的外号是什么。", "weight": 1 },
        { "name": "在感情和面包中，你会选取哪个？为什么？", "weight": 1 },
        { "name": "你最不开心的时候会有什么表现？", "weight": 1 },
        { "name": "最珍爱的人是你右手的哪一个手指？", "weight": 1 },
        { "name": "当你最不知道穿什么颜色的时候，你会选取什么颜色？", "weight": 1 },
        { "name": "你此刻穿什么牌子的衣服。", "weight": 1 },
        { "name": "今年你最后悔的一件事是什么？", "weight": 1 },
        { "name": "如果你爱的人不爱你怎样办？", "weight": 1 },
        { "name": "当你被我点名的时候是什么情绪？", "weight": 1 },
        { "name": "目前最大的愿望？", "weight": 1 },
        { "name": "如果时刻能倒流你期望回到哪一时刻？", "weight": 1 },
        { "name": "你有恨过谁吗？", "weight": 1 },
        { "name": "如果有来生，你选取当？", "weight": 1 },
        { "name": "在你眼里，我是个怎样的人？我要听实话啦…", "weight": 1 },
        { "name": "你心目中理想的爱人是什么样貌呢？", "weight": 1 },
        { "name": "你最想要的样东西", "weight": 1 },
        { "name": "最喜欢的食物是什么", "weight": 1 },
        { "name": "最喜欢哪部电影？", "weight": 1 },
        { "name": "世界末日，你会幸存，并且你能够救一个人，你会怎样做？", "weight": 1 },
        { "name": "如果有一天我和你吵架，你会怎样办？", "weight": 1 },
        { "name": "你的爱人要出国，你会怎样做？", "weight": 1 },
        { "name": "你认为多交兄弟姐妹的好处在哪", "weight": 1 },
        { "name": "想过自我以后是干什么的吗？你的理想职业是什么？", "weight": 1 },
        { "name": "去你喜欢的人家里。想拉肚子怎样办。", "weight": 1 },
        { "name": "初吻是在什么状况下没有的。", "weight": 1 },
        { "name": "如果从天而降枚金币，你的第一反应是什么？", "weight": 1 },
        { "name": "与喜欢的人见面，想要穿成什么样？", "weight": 1 },
        { "name": "在你心中谁最可信？", "weight": 1 },
        { "name": "如果有一天我对你说我爱上你了，你怎样办？", "weight": 1 },
        { "name": "比较喜欢父亲还是母亲？", "weight": 1 },
        { "name": "情人节最想收到什么礼物？", "weight": 1 },
        { "name": "如果让你选取做一个电影中的主角，你会选谁呢？", "weight": 1 },
        { "name": "哭得最悲哀的'是哪一次？为什么？", "weight": 1 },
        { "name": "你会选取你爱的人还是爱你的人？", "weight": 1 },
        { "name": "写首自我最最喜爱的歌？", "weight": 1 },
        { "name": "最想实现的三个愿望是什么？", "weight": 1 },
        { "name": "远距离恋爱是否注定要分开？那么如果喜欢上一个遥远国度的人，你是否会选取跟他走？", "weight": 1 },
        { "name": "对你而言，感情和友情哪个比较重要？", "weight": 1 },
        { "name": "在自我最爱的人面前做过最囧的事是什么。", "weight": 1 },
        { "name": "你的小癖好是什么。", "weight": 1 },
        { "name": "到目前为止你做过最疯狂的事是？", "weight": 1 },
        { "name": "喜欢看什么动画片？", "weight": 1 },
        { "name": "最想感谢的人是谁？", "weight": 1 },
        { "name": "你期望谁得到幸福？", "weight": 1 },
        { "name": "你觉得自我长的如何。", "weight": 1 },
        { "name": "如果能预知未来，你最不期望看见的是什么？", "weight": 1 },
        { "name": "你觉得最美的画面是什么？", "weight": 1 },
        { "name": "如果给你一个机会去世界上任何一个地方旅行你会去、", "weight": 1 },
        { "name": "如果跟你喜欢的人约会，碰到前任的男（女）兄弟姐妹，会有什么表现？", "weight": 1 },
        { "name": "你最喜欢的歌曲是哪首？", "weight": 1 },
        { "name": "你在乎别人看你的眼光吗？会为了众人的反对放下自我想要的东西或人吗？", "weight": 1 },
        { "name": "你的梦中情人是谁。", "weight": 1 },
        { "name": "和恋人在一齐的时候叫错了名字怎样办。", "weight": 1 },
        { "name": "最长一次连续睡着了多久。", "weight": 1 },
        { "name": "如果有一天，你性命中最重要的东西离你而去了，你会怎样办？", "weight": 1 },
        { "name": "世上真的有真爱吗？你眼中的真爱是什么样的？", "weight": 1 },
        { "name": "最奢侈的一次消费是什么。", "weight": 1 },
        { "name": "我和你恋人同时约你，你会陪谁？", "weight": 1 },
        { "name": "最后一次发自内心的笑是什么时候？", "weight": 1 },
        { "name": "目前你最大的愿望是什么。", "weight": 1 },
        { "name": "如果你的情敌掉水里了，你会怎么样。", "weight": 1 },
        { "name": "你喜欢看什么动画片（说出三种）。", "weight": 1 },
        { "name": "最想感谢的人是谁。", "weight": 1 },
        { "name": "从现在开始起说十句假话（比如，我有十米高……）。", "weight": 1 },
        { "name": "最喜欢的食物是什么。", "weight": 1 },
        { "name": "说说你做过最糗的事什么？", "weight": 1 },
        { "name": "大学一共挂过几门课？", "weight": 1 },
        { "name": "最奢侈的一次消费是什么？", "weight": 1 },
        { "name": "此刻你最喜欢的人是谁？", "weight": 1 },
        { "name": "被人冤枉时，怎么办？", "weight": 1 },
        { "name": "你现在的存款是多少？", "weight": 1 },
        { "name": "吃下每个人为你夹得菜？", "weight": 1 },
        { "name": "像一位异性表白3分钟？", "weight": 1 },
        { "name": "有住院经历吗？", "weight": 1 },
        { "name": "最喜欢的食物是什么？", "weight": 1 },
        { "name": "你希望未来有几个孩子？", "weight": 1 },
        { "name": "你作弊使用过哪些手段？", "weight": 1 },
        { "name": "你最喜欢的歌曲是哪首？", "weight": 1 },
        { "name": "你觉得自己长的如何？", "weight": 1 },
        { "name": "最喜欢的颜色？", "weight": 1 },
        { "name": "你喜欢运动么？", "weight": 1 },
        { "name": "世界上最大的悲剧是什么？", "weight": 1 },
        { "name": "目前最大的愿望？", "weight": 1 },
        { "name": "做过最丢脸的事情？", "weight": 1 },
        { "name": "你喜欢我什么？", "weight": 1 },
        { "name": "觉得失去什么最可怕？", "weight": 1 },
        { "name": "写首自我最最喜爱的歌？", "weight": 1 },
        { "name": "你认为真爱是什么样子的？", "weight": 1 },
        { "name": "你最喜欢的小说是什么？", "weight": 1 },
        { "name": "上厕所后洗手么？", "weight": 1 },
        { "name": "每天上网几个小时？", "weight": 1 },
        { "name": "如何向喜欢的人表白？", "weight": 1 },
        { "name": "你的梦中情人是谁？", "weight": 1 },
        { "name": "你难过的时候会做什么？", "weight": 1 },
        { "name": "如果有来生，你选择当？", "weight": 1 },
        { "name": "对自己那个部位最不满意？", "weight": 1 },
        { "name": "在场你有喜欢的人吗？", "weight": 1 },
        { "name": "你觉得自我长的如何？", "weight": 1 },
        { "name": "你眼中的他是什么样的人？", "weight": 1 },
        { "name": "你对另一半的要求有哪些？", "weight": 1 },
        { "name": "你最喜欢的季节是什么？", "weight": 1 },
        { "name": "你有什么小癖好？", "weight": 1 },
        { "name": "最想感谢的人是谁？", "weight": 1 },
        { "name": "你相信一见钟情么？", "weight": 1 },
        { "name": "你最喜欢的食物是什么？", "weight": 1 },
        { "name": "我们在一起你快乐吗？", "weight": 1 },
        { "name": "唱青藏高原最后一句？", "weight": 1 },
        { "name": "你最喜欢的电影是什么？", "weight": 1 },
        { "name": "朋友和男/女朋友哪个重要？", "weight": 1 },
        { "name": "你特别在意你男朋友什么？", "weight": 1 },
        { "name": "曾经看了流泪的电影？", "weight": 1 },
        { "name": "你会在意身高问题吗？", "weight": 1 },
        { "name": "你暗恋过多少个人？", "weight": 1 },
        { "name": "你最想要的5样东西？", "weight": 1 },
        { "name": "你作弊使用过的最高招？", "weight": 1 },
        { "name": "你选男朋友首先看重什么？", "weight": 1 },
        { "name": "讲述未来5年的事业规划？", "weight": 1 },
        { "name": "你喜欢谁？", "weight": 1 },
        { "name": "你理想中的婚礼是怎么样的？", "weight": 1 },
        { "name": "哭得最伤心的是哪次？", "weight": 1 },
        { "name": "最完美的周末是怎么样的？", "weight": 1 },
        { "name": "你比较喜欢父亲还是母亲？", "weight": 1 },
        { "name": "你最关心的异性是谁？", "weight": 1 },
        { "name": "你此刻穿什么牌子的内衣？", "weight": 1 },
        { "name": "你喜欢你的对象粘着你吗？", "weight": 1 },
        { "name": "在你心中谁最可信？", "weight": 1 },
        { "name": "怎样看待倒追自己的女生？", "weight": 1 },
        { "name": "说说你对我的真实评价？", "weight": 1 },
        { "name": "让你最感动的事是什么？", "weight": 1 },
        { "name": "你最喜欢什么样的男生？", "weight": 1 },
        { "name": "你最喜欢吃什么？", "weight": 1 },
        { "name": "自己最丢人的事？", "weight": 1 },
        { "name": "你最喜欢的小说是什么？", "weight": 1 },
        { "name": "喜欢看什么动画片？", "weight": 1 },
        { "name": "最喜欢的零食？", "weight": 1 },
        { "name": "你们家里谁的脾气最大？", "weight": 1 },
        { "name": "在座你最想打的人是谁？", "weight": 1 },
        { "name": "如果我哭了你怎么办？", "weight": 1 },
        { "name": "你希望未来有几个孩子？", "weight": 1 },
        { "name": "你最奇怪的癖好是什么？", "weight": 1 },
        { "name": "你想拥有哪种超能力？", "weight": 1 },
        { "name": "你希望你现在是多少岁？", "weight": 1 },
        { "name": "你最怕的事情是什么？", "weight": 1 },
        { "name": "晚上睡觉要上几次厕所？", "weight": 1 },
        { "name": "你理想中的工作是什么？", "weight": 1 },
        { "name": "你最喜欢的歌曲是哪首？", "weight": 1 },
        { "name": "有考虑过结婚吗？", "weight": 1 },
        { "name": "你今天可以吃冰淇淋吗？", "weight": 1 },
        { "name": "旅行过的地方，最爱哪里？", "weight": 1 },
        { "name": "你最钟爱的电影是哪一部？", "weight": 1 },
        { "name": "你小时候的绰号是什么？", "weight": 1 },
        { "name": "你对姐弟恋有什么看法？", "weight": 1 },
        { "name": "觉得单身好吗？", "weight": 1 },
        { "name": "你最喜欢什么样的男生？", "weight": 1 },
        { "name": "大学时候挂过几门课？", "weight": 1 },
        { "name": "说出你撒过的最严重的谎？", "weight": 1 },
        { "name": "你最喜欢的季节是什么？", "weight": 1 },
        { "name": "打算什么时候结婚？", "weight": 1 },
        { "name": "情人节最想收到什么礼物？", "weight": 1 },
        { "name": "如果有来生你选择当？", "weight": 1 },
        { "name": "你觉得活着的意义是什么？", "weight": 1 }
    ]; // 名字和对应的权重列表

    const totalWeight = namesWithWeights.reduce((sum, { weight }) => sum + weight, 0); // 计算总权重

    const drawnNameDiv = document.getElementById('drawn-name');
    const drawButton = document.getElementById('draw-button');

    drawButton.addEventListener('click', function () {
        let randomValue = Math.random() * totalWeight;
        let drawnName;

        // 使用some方法遍历namesWithWeights数组，找到对应的name
        namesWithWeights.some(({ name, weight }) => {
            if (randomValue - weight <= 0) {
                drawnName = name;
                return true; // 找到名字后退出some方法
            }
            randomValue -= weight;
            return false;
        });

        if (drawnName) {
            // 生成随机颜色
            const randomColor = getRandomColor();

            // 显示抽中的名字，并应用随机颜色
            drawnNameDiv.innerHTML = `<p style="color: ${randomColor};"> ${drawnName} </p>`;
        } else {
            drawnNameDiv.innerHTML = '<p>没有名字被抽中</p>';
        }
    });

    // 生成随机颜色的函数
    function getRandomColor() {
        const red = Math.floor(Math.random() * 256);
        const green = Math.floor(Math.random() * 256);
        const blue = Math.floor(Math.random() * 256);
        return `rgb(${red}, ${green}, ${blue})`; // 返回rgb颜色格式的字符串
    }
});